package com.school.hjt.schoolclasscard.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.school.hjt.schoolclasscard.R;
import com.school.hjt.schoolclasscard.db.SchArticle;

import java.util.List;

/**
 * Created by xqx on 2018/1/22.
 */

public class NewsAdapter extends BaseAdapter {
    private Context mContext;
    private List<SchArticle> list;
    public NewsAdapter(Context mContext, List<SchArticle> list) {
        this.mContext = mContext;
        this.list = list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHander viewHander;
        if (convertView==null){
            viewHander=new ViewHander();
            convertView= View.inflate(mContext, R.layout.news_item,null);
            viewHander.iv_arc=convertView.findViewById(R.id.iv_arc);
            viewHander.tv_title=convertView.findViewById(R.id.tv_title);
            viewHander.tv_content=convertView.findViewById(R.id.tv_content);
            convertView.setTag(viewHander);
        }else{
            viewHander= (ViewHander) convertView.getTag();
        }
        Glide.with(mContext).load(list.get(position).getImage_path()).into(viewHander.iv_arc);
        viewHander.tv_title.setText(list.get(position).getTitle());
        viewHander.tv_content.setText(list.get(position).getContent());
        return convertView;
    }
    class ViewHander{
        ImageView iv_arc;
        TextView tv_title,tv_content;
    }


}
